package com.course.business.controller.web.discusspost;


import com.course.server.domain.Course;
import com.course.server.dto.PageDto;
import com.course.server.dto.ResponseDto;
import com.course.server.service.CourseService;
import com.course.server.service.discusspost.DiscussPostService;
import com.course.server.util.CommunityConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/web")
public class HomeController implements CommunityConstant {

    @Autowired
    private DiscussPostService discussPostService;

    @Autowired
    private CourseService courseService;

    //orderMode:0最新，1最热。
    @RequestMapping(path = "/course_discusspost")
    public ResponseDto getIndexPage(@RequestParam(name = "courseId", defaultValue = "") String courseId,@RequestParam(name = "orderMode", defaultValue = "0") int orderMode, @RequestBody PageDto pageDto) {
        ResponseDto responseDto = new ResponseDto();
        Map<String,Object> dto = discussPostService.findDiscussPosts(pageDto,  orderMode,"",courseId);//userId=""表示不用userId条件过滤
        Course course=courseService.selectCourseById(courseId);
        dto.put("course",course);
        responseDto.setContent(dto);
        return responseDto;
    }
}
